package org.jod.spike.swing;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

public class ButtonEventMain {

    /**
     * @param args
     */
    public static void main(String[] args) {

            new ButtonEventMain();

    }

    
    public ButtonEventMain() {
        JFrame frame = new JFrame("Button Sample");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JButton button = new JButton("VAI");
        
        
        
         new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
              System.out.println("I was selected.");
            }
          };        
          
          button.addActionListener(new MyAction());

          Container contentPane = frame.getContentPane();
          contentPane.add(button, BorderLayout.SOUTH);
          frame.setSize(300, 100);
          frame.setVisible(true);
    }
    
    public class MyAction implements ActionListener {

        public void actionPerformed(ActionEvent arg0) {

            System.out.println(arg0.getActionCommand());
            
            System.out.println("I was selected pippo.");
            
        }
        
    }
}
